/**
 * 
 */
package alibaba;

import java.beans.XMLEncoder;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.security.MessageDigest;
import java.util.HashMap;
import java.util.Map;

/**
 * @author ronenkat
 *
 */
public class Listing {

	/**
	 * @param listOfFiles
	 */
	public Listing(Map<String, ListingEntry> listOfFiles) {
		super();
		this.listOfFiles = listOfFiles;
	}

	/**
	 */
	public Listing() {
		super();
		this.listOfFiles = null;
	}

	private Map<String,ListingEntry> listOfFiles;   
	//Vector<ListingEntry> listOfFiles;

	/**
	 * @return the listOfFiles
	 */
	public Map<String, ListingEntry> getListOfFiles() {
		return listOfFiles;
	}

	/**
	 * @param listOfFiles the listOfFiles to set
	 */
	public void setListOfFiles(Map<String, ListingEntry> listOfFiles) {
		this.listOfFiles = listOfFiles;
	}

	/**
	 * Write the backup server meta information repository to disk
	 * @param filename
	 * @param listing
	 */
	public static void writeListing(String filename, Listing listing) {
	}
	
	/**
	 * Read the backup server meta information repository from disk
	 * @param filename
	 * @return
	 */
	public static Listing readListing(String filename) {
		return null;
	}
	
	public static void main(String[] args) throws Exception {

		MessageDigest md = MessageDigest.getInstance("SHA-1");
		byte[] sha1hash = new byte[20];
		md.update("hello".getBytes());
		sha1hash = md.digest();
		Listing listing = new Listing();
		listing.listOfFiles = new HashMap<String,ListingEntry>();

		ListingEntry a = new ListingEntry("abc.txt", "abc.txt", sha1hash);
		listing.listOfFiles.put( "abc.txt", a);
		listing.listOfFiles.put( "222.txt", new ListingEntry("222.txt", "222.txt", sha1hash));

		XMLEncoder e = new XMLEncoder(
				new BufferedOutputStream(
						new FileOutputStream("c:\\temp\\Test.xml")));
		e.writeObject( listing );
		e.close(); 
	}
}
